home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
msoftapp.zip
/
PRECOMP.TXT
< prev
next >
Wrap
Text File
|
1993-04-15
|
3KB
|
48 lines
Precompiled Headers
Precompiled headers are a means of greatly speeding compile time by
compiling header files only once into a precompiled header file (PCH)
and thereafter using the precompiled header for each build. Visual C++
provides two different ways to implement precompiled headers. You
can use the new simplified method (/YX), or you can use the more flexible
method (/Yc and /Yu), for more control and for mixed-
language (C and C++) source files. These choices can be made from the
Visual WorkBench's Option Project Compiler Precompiled Headers dialog.
Due to space restrictions, only the simplified method is discussed here.
When applied to a single source file, /YX simply compiles all
preprocessor directives (such as #include), from the start of the file
to the start of C or C++ code, into a file named MSVC.PCH (which can be
renamed using /Fp). In Visual Workbench you select the Automatic Use of
Precompiled Headers compiler option to enable /YX.
When applied to multiple source files, /YX will first create a
precompiled header file using the #includes from the first file. On
each subsequent source file it will examine the order of the #include
files and check that they match the order of the files in the
precompiled header file. If they match directly, the precompiled
header file is used as is. This is the most efficient way to use /YX.
If a subset of the #include files are in common, the compiler
automatically pares down the precompiled header file to only represent
the common subset of #include files and uses that. Generally, after
comparing two source files a usable common subset will emerge. If no
#include files are found in common, the PCH file is not used and
compilation proceeds.
The advantage of using Automatic Precompiled Headers is that it will
quietly work to build and use an efficient precompiled header file on
any collection of source files. However, you can achieve better build
times if you are willing to edit your source files. You will get the
most efficient build times by listing the same include statements in
the same order in all project source files. If you don't do this for
all include statements, at least do it for all include files you want
precompiled and put them first. Generally, you should include all the
big include files that you use, like WINDOWS.H or AFXWIN.H, in this subset.
Another useful technique is to place all these large include files that
are unlikely to change into their own header file and then include this
master include file at the beginning of each source file followed by
any #include statements that are needed locally. This gives you an
easy to maintain file structure that works very well with Auto PCH.
This is exactly what AppWizard does with the file STDAFX.H that it
includes at the beginning of each source file.